

layui.use(['table','form', 'layedit', 'laydate','jquery','layer'], function () {
    var table = layui.table
        ,form = layui.form
        // ,layer = layui.layer
        ,layer = parent.layer === undefined ? layui.layer : parent.layer
        ,laydate = layui.laydate
        ,$ = layui.jquery;
        form.render();

    $.ajax({
        type: "get",
        url: "../template/selectPassTempletByUserId.do?userId="+id,
        contentType: "application/json",
        async: false,
        // data: JSON.stringify(data.field),
        success: function (res) {
            if (res.resultCode == 10000) {
                var $html = "";
                $.each(res.data, function (index, item) {
                        $html += "<option value='" + item.templetNo + "'>" + item.templetCnName+'('+item.templetNo+')'+ "</option>";
                        // alert($html);
                });
                $("#template-select").append($html);
                form.render();
            } else {
                layer.msg(res.msg, {icon: 2});
            }
        },
    });


    form.on('submit(demo1)', function(data){

        // alert(JSON.stringify(data.field));
        $.ajax({
            type: "post",
            url: ctx+"/msgdetail/create.do",
            contentType: "application/json",
            async: false,
            data: JSON.stringify(data.field),
            success: function (res) {
                if (res.resultCode == 10000) {
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                    parent.layer.msg(res.msg, {icon: 1});
                    parent.location.reload()
                } else {
                    layer.msg(res.msg, {icon: 2});
                }
            },
        });
    })





});